import type { SopTerminal } from "@/pages/mes/sop/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //终端名称
  name?: string;
  //车间ID
  workshopId?: number;
  //产线ID
  lineId?: number;
  //工位ID
  stationId?: number;
  //终端IP
  ip?: string;
  //状态
  status?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: SopTerminal[];
}

const list = (data: SopTerminal): Promise<SopTerminal[]> =>
  apiClient.post({
    url: "/mes/terminal/list",
    data
});

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/mes/terminal/pageList",
    data
});

const getInfo = (id: React.Key): Promise<SopTerminal> =>
  apiClient.get({
    url: `/mes/terminal/${id}`
});

const add = (data: SopTerminal): Promise<SopTerminal> =>
  apiClient.post({
    url: "/mes/terminal",
    data
});

const update = (data: SopTerminal): Promise<SopTerminal> =>
  apiClient.put({
    url: "/mes/terminal",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/mes/terminal",
    params: {
    ids: ids.join(",")
  }
});
export const sopTerminalService = {
  list,
  pageList,
  getInfo,
  add,
  update,
  remove,
};

export default sopTerminalService;